package com.ibm.productivity.tools.blogplugin.meta;


public class Article implements Comparable<Article>{
	private int  id;
	private String title;
	private String author;
	private String content;
	private boolean changed;
	private IBlog blog = null;
	
	public Article(String title, String author, String content){		
		this.title = title;
		this.author = author;
		this.content = content;
		changed = false;
	}
	
	public Article(String title, String content){		
		this(title, null, content);
	}
	
	public boolean getChanged(){
		return changed;
	}

	public void setChanged(boolean changed) {
		this.changed = changed;
	}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		changed = true;
		this.title = title;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		changed = true;
		this.author = author;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		changed = true;
		this.content = content;
	}

	public int getId() {
		return id;
	}

	public IBlog getBlog() {
		return blog;
	}

	public void setBlog(IBlog blog) {
		this.blog = blog;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int compareTo(Article a) {
		if (this.id == a.id && this.blog == a.blog) return 0;
		return this.id - a.id;
	}
	
	public void delete() throws BlogException {
		if (this.blog == null) 
			throw new BlogException("The article belongs null.");
		this.blog.deleteArticle(this);
		this.blog = null;
	}

	public void update() throws BlogException {
		if (this.blog == null) 
			throw new BlogException("The article belongs null.");
		this.blog.updateArticle(this);
	}

	public Comment postComment(String content) throws BlogException {
		if (this.blog == null) 
			throw new BlogException("The article belongs null.");
		return this.blog.postComment(this, content);
	}
	
	public Comment [] getComments() throws BlogException {
		if (this.blog == null) 
			throw new BlogException("The article belongs null.");
		return this.blog.getComments(this);		
	}
	
	public void deleteComment(Comment comment) throws BlogException {
		if (this.blog == null) 
			throw new BlogException("The article belongs null.");
		this.blog.deleteComment(this, comment);
	}
	
}
